// Bristleback plugin - Copyright (c) 2010 bristleback.googlecode.com
// ---------------------------------------------------------------------------
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published by the
// Free Software Foundation; either version 3 of the License, or (at your
// option) any later version.
// This library is distributed in the hope that it will be useful,
// but without any warranty; without even the implied warranty of merchantability
// or fitness for a particular purpose.
// You should have received a copy of the GNU Lesser General Public License along
// with this program; if not, see <http://www.gnu.org/licenses/lgpl.html>.
// ---------------------------------------------------------------------------
package pl.bristleback.server.bristle.messages;

import org.apache.log4j.Logger;

import java.util.Map;

/**
 * Message senders exporter holds all senders loaded by {@link pl.bristleback.server.bristle.config.MessageContainerResolver} implementation.
 * User can not add message sender directly, so it's guaranteed that every sender has set server and dispatcher.
 * In case when message sender is a Spring bean, it might be a better idea to inject sender using Spring context.
 * <p/>
 * Created on: 2010-09-26 10:47:10 <br/>
 *
 * @author Wojciech Niemiec
 */
public final class MessageSendersExporter {
  private static Logger log = Logger.getLogger(MessageSendersExporter.class.getName());

  private static Map<String, MessageSender> senders;

  private MessageSendersExporter() {
    throw new UnsupportedOperationException();
  }


  /**
   * Method not visible to users. It sets message senders.
   *
   * @param s senders map
   */
  static void setMessageSenders(Map<String, MessageSender> s) {
    senders = s;
  }

  /**
   * Gets sender for given sender name. Returns null if no sender with given name can be found.
   *
   * @param senderName sender name
   * @return message sender implementation.
   */
  public static MessageSender getMessageSender(String senderName) {
    return senders.get(senderName);
  }
}
